package com.sun.hunk.hibernate.domain.impl;

import com.sun.hunk.hibernate.domain.Charge;
import com.sun.hunk.hibernate.domain.Client;
import com.sun.hunk.hibernate.domain.Invoice;
import com.sun.hunk.hibernate.domain.User;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author sunil
 */
@Entity
@Table(name = "invoice")
public class InvoiceImpl implements Invoice {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Column(name = "created_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;
    @Column(name = "invoice_no")
    private String invoiceNo;
    @Column(name = "date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
    @Column(name = "iec_code")
    private String iecCode;
    @Column(name = "order_no")
    private String orderNo;
    @Column(name = "order_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date orderDate;
    @Column(name = "reference")
    private String reference;
    @Column(name = "ad_code")
    private String adCode;
    @Column(name = "origin_country")
    private String originCountry;
    @Column(name = "destination_country")
    private String destinationCountry;
    @Column(name = "pre_by")
    private String preBy;
    @Column(name = "terms_of_delivery")
    private String termsOfDelivery;
    @Column(name = "vessel_no")
    private String vesselNo;
    @Column(name = "freight_no")
    private String freightNo;
    @Column(name = "pod")
    private String pod;
    @Column(name = "por")
    private String por;
    @Column(name = "pol")
    private String pol;
    @Column(name = "destination")
    private String destination;
    @Column(name = "declaration")
    private String declaration;
    @JoinColumn(name = "consignee_id", referencedColumnName = "id")
    @OneToOne(cascade = CascadeType.ALL, targetEntity = ClientImpl.class)
    private Client consignee = new ClientImpl();
    @JoinColumn(name = "consignor_id", referencedColumnName = "id")
    @OneToOne(cascade = CascadeType.ALL, targetEntity = ClientImpl.class)
    private Client consignor = new ClientImpl();
    @JoinColumn(name = "created_by", referencedColumnName = "id")
    @ManyToOne(cascade = CascadeType.ALL, targetEntity = UserImpl.class)
    private User createdBy;
    @OneToMany(mappedBy = "invoice", targetEntity = ChargeImpl.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private List<Charge> charges = new ArrayList<Charge>();

    public InvoiceImpl() {
        consignee = DomainFactory.getClient();
        consignor = DomainFactory.getClient();
    }

    public InvoiceImpl(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getInvoiceNo() {
        return invoiceNo;
    }

    public void setInvoiceNo(String invoiceNo) {
        this.invoiceNo = invoiceNo;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getIecCode() {
        return iecCode;
    }

    public void setIecCode(String iecCode) {
        this.iecCode = iecCode;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public Date getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(Date orderDate) {
        this.orderDate = orderDate;
    }

    public String getReference() {
        return reference;
    }

    public void setReference(String reference) {
        this.reference = reference;
    }

    public String getOriginCountry() {
        return originCountry;
    }

    public void setOriginCountry(String originCountry) {
        this.originCountry = originCountry;
    }

    public String getDestinationCountry() {
        return destinationCountry;
    }

    public void setDestinationCountry(String destinationCountry) {
        this.destinationCountry = destinationCountry;
    }

    public String getPreBy() {
        return preBy;
    }

    public void setPreBy(String preBy) {
        this.preBy = preBy;
    }

    public String getTermsOfDelivery() {
        return termsOfDelivery;
    }

    public void setTermsOfDelivery(String termsOfDelivery) {
        this.termsOfDelivery = termsOfDelivery;
    }

    public String getVesselNo() {
        return vesselNo;
    }

    public void setVesselNo(String vesselNo) {
        this.vesselNo = vesselNo;
    }

    public String getFreightNo() {
        return freightNo;
    }

    public void setFreightNo(String freightNo) {
        this.freightNo = freightNo;
    }

    public String getPod() {
        return pod;
    }

    public void setPod(String pod) {
        this.pod = pod;
    }

    public String getPor() {
        return por;
    }

    public void setPor(String por) {
        this.por = por;
    }

    public String getPol() {
        return pol;
    }

    public void setPol(String pol) {
        this.pol = pol;
    }

    public String getDestination() {
        return destination;
    }

    public void setDestination(String destination) {
        this.destination = destination;
    }

    public String getDeclaration() {
        return declaration;
    }

    public void setDeclaration(String declaration) {
        this.declaration = declaration;
    }

    public Client getConsignee() {
        return consignee;
    }

    public void setConsignee(Client consignee) {
        this.consignee = consignee;
    }

    public Client getConsignor() {
        return consignor;
    }

    public void setConsignor(Client consignor) {
        this.consignor = consignor;
    }

    public User getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(User createdBy) {
        this.createdBy = createdBy;
    }

    public List<Charge> getCharges() {
        return charges;
    }

    public void setCharges(List<Charge> charges) {
        this.charges = charges;
    }

    public void addCharge(Charge charge) {
        charge.setInvoice(this);
        this.charges.add(charge);
    }

    public String getAdCode() {
        return adCode;
    }

    public void setAdCode(String adCode) {
        this.adCode = adCode;
    }


    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof InvoiceImpl)) {
            return false;
        }
        InvoiceImpl other = (InvoiceImpl) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.sun.hunk.hibernate.domain.impl.Invoice[id=" + id + "]";
    }
}
